package com.kensure.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import co.kensure.frame.ResultInfo;
import co.kensure.frame.ResultRowInfo;
import co.kensure.frame.ResultRowsInfo;
import co.kensure.http.RequestUtils;
import co.kensure.mem.PageInfo;

import com.alibaba.fastjson.JSONObject;
import com.kensure.shike.chongzhi.query.SKZhangQuery;
import com.kensure.shike.user.model.SKUser;
import com.kensure.shike.user.service.SKUserFRService;
import com.kensure.shike.user.service.SKUserService;
import com.kensure.shike.zhang.model.SKUserZhang;
import com.kensure.shike.zhang.service.SKUserZhangService;

/**
 * 用户的账务流水
 * 
 * @author fankaidi
 *
 */
@Controller
@RequestMapping(value = "zhang")
public class SKZhangController {

	@Resource
	private SKUserZhangService sKUserZhangService;

	@Resource
	private SKUserService sKUserService;
	@Resource
	private SKUserFRService sKUserFRService;

	/**
	 * 管理员获取提现列表
	 */
	@ResponseBody
	@RequestMapping(value = "allzhanglist.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo alltixianlist(HttpServletRequest req, HttpServletResponse rep) {
		JSONObject json = RequestUtils.paramToJson(req);
		SKZhangQuery query = JSONObject.parseObject(json.toJSONString(), SKZhangQuery.class);
		PageInfo page = JSONObject.parseObject(json.toJSONString(), PageInfo.class);
		List<SKUserZhang> list = sKUserZhangService.selectAllZhangList(query, page);
		long count = sKUserZhangService.selectAllZhangCount(query);
		return new ResultRowsInfo(list, count);
	}

	/**
	 * 用户查看自己的账务列表
	 */
	@ResponseBody
	@RequestMapping(value = "userzhanglist.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo userzhanglist(HttpServletRequest req, HttpServletResponse rep) {
		SKUser user = sKUserService.getUser();
		List<SKUserZhang> list = sKUserZhangService.selectByUser(user, null, 1);
		return new ResultRowsInfo(list);
	}

	/**
	 * 用户查看自己未到账佣金
	 */
	@ResponseBody
	@RequestMapping(value = "userfanli.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo userfanli(HttpServletRequest req, HttpServletResponse rep) {
		SKUser user = sKUserService.getUser();
		Double yj = sKUserFRService.selectUserYjSum(user);
		return new ResultRowInfo(yj);
	}

	/**
	 * 用户查看自己佣金列表
	 */
	@ResponseBody
	@RequestMapping(value = "userfanlilist.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo userfanlilist(HttpServletRequest req, HttpServletResponse rep) {
		SKUser user = sKUserService.getUser();
		List<SKUserZhang> list = sKUserZhangService.selectByUserAndBusi(user);
		return new ResultRowsInfo(list);
	}

	/**
	 * 30天财务数据
	 */
	@ResponseBody
	@RequestMapping(value = "cwsj.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo cwsj(HttpServletRequest req, HttpServletResponse rep) {
		List<Map<String, Object>> listmap = sKUserZhangService.caiwushuju();
		return new ResultRowsInfo(listmap);
	}
}
